package com.example.boot.quartz.config;

import com.example.boot.quartz.task.*;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;

/**
 * 定时任务配置类
 *
 * @author ding
 * @since 2024/7/15
 */
@Configuration
public class QuartzConfig {
    //工作明细  晚上十点发送作业
//    @Bean
    public JobDetail jobDetail() {
        //构建工作  newJob指定工作内容  storeDurably设置持久化
        return JobBuilder
                .newJob(MyQuartz.class)
                .storeDurably()
                .build();
    }
    //触发器
//    @Bean
    public Trigger trigger() {
        //构建定时任务，并指定cron表达式
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 22 * * ?");

        //构建触发器，并绑定工作明细，以及定时任务
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withSchedule(scheduleBuilder)
                .build();
    }

    //定时任务:项目结束提醒
    @Bean
    public JobDetail jobDetail2() {
        return JobBuilder
                .newJob(ProjectEmail.class)
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger trigger2() {
        //每天的半夜十二点发送项目提醒邮件
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 * * ? ");

        return TriggerBuilder.newTrigger()
                .forJob(jobDetail2())
                .withSchedule(scheduleBuilder)
                .build();
    }

    //定时任务，每天凌晨两点删除多余上传的图片
    @Bean
    public JobDetail jobDetail3(){
        return JobBuilder.newJob(DeleteImg.class)
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger trigger3(){
        //每天的凌晨两点进行多处图片的清除
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 2 * * ?");

        return TriggerBuilder.newTrigger()
                .forJob(jobDetail3())
                .withSchedule(scheduleBuilder)
                .build();
    }

    //定时任务 ，每天零点删除昨日的uv访问量shuju
    @Bean
    public JobDetail jobDetail4() {
        return JobBuilder.newJob(UVCount.class)
                .storeDurably()
                .build();
    }
    @Bean
    public  Trigger trigger4() {
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 * * ?");

        return TriggerBuilder.newTrigger()
                .forJob(jobDetail4())
                .withSchedule(scheduleBuilder)
                .build();
    }

    //定时任务 每天零点阶段结束提醒
    @Bean
    public JobDetail jobDetail5() {
        return JobBuilder
                .newJob(StageEmail.class)
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger trigger5() {
        //每天的半夜十二点发送项目提醒邮件
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 * * ? ");

        return TriggerBuilder.newTrigger()
                .forJob(jobDetail5())
                .withSchedule(scheduleBuilder)
                .build();
    }

}
